package sdk

import "strings"

// VulnerabilityWorkerReport represent a vulnerability report
type VulnerabilityWorkerReport struct {
	Summary         map[string]int64 `json:"summary"`
	Vulnerabilities []Vulnerability  `json:"vulnerabilities"`
	Type            string           `json:"type"`
}

// Vulnerability represents vulnerabilities on an application
type Vulnerability struct {
	ID            int64  `json:"id" db:"id"`
	ApplicationID int64  `json:"application_id" db:"application_id"`
	Title         string `json:"title" db:"title"`
	Description   string `json:"description" db:"description"`
	CVE           string `json:"cve" db:"cve"`
	Link          string `json:"link" db:"link"`
	Component     string `json:"component" db:"component"`
	Version       string `json:"version" db:"version"`
	Origin        string `json:"origin" db:"origin"`
	Severity      string `json:"severity" db:"severity"`
	FixIn         string `json:"fix_in" db:"fix_in"`
	Ignored       bool   `json:"ignored" db:"ignored"`
	Type          string `json:"type" db:"type"`
}

const (
	SeverityUnknown    string = "unknown"
	SeverityNegligible string = "negligible"
	SeverityLow        string = "low"
	SeverityMedium     string = "medium"
	SeverityHigh       string = "high"
	SeverityCritical   string = "critical"
	SeverityDefcon1    string = "defcon1"
)

// ToVulnerabilitySeverity converts string to good severity name
func ToVulnerabilitySeverity(s string) string {
	s = strings.ToLower(s)
	switch s {
	case SeverityNegligible, SeverityLow, SeverityMedium, SeverityHigh, SeverityCritical, SeverityDefcon1:
		return s
	case "Moderate":
		return SeverityMedium
	default:
		return SeverityUnknown
	}
}
